<template>
	<view class="c-wrap">
		<view class="c-block active">
			<view class="c-album">
				<view class="c-album__avatar">
					<image v-if="$u.clogin.getIsLogined()&&sr.userinfo.avatarurl!=null&&sr.userinfo.avatarurl!=''"
						:src="sr.userinfo.avatarurl" mode="" style="width: 65px;height: 65px;"></image>
					<image v-if="!$u.clogin.getIsLogined()||sr.userinfo.avatarurl==null||sr.userinfo.avatarurl==''"
						src="/static/assets/clogin/image/default-avatar.jpg" mode="" style="width: 65px;height: 65px;">
					</image>
				</view>
				<view class="c-album__content" v-if="$u.clogin.getIsLogined()">
					<view class="c-title" style="padding-top: 5px;">{{sr.userinfo.nickname}} </view>
					<view class="c-content">{{sr.userinfo.mobile}}</view>
					<view class="c-content">{{$t('clogin.label.jointime')}}:
						{{$u.timeFormat(sr.userinfo.jointime, 'yyyy/mm/dd hh:MM')}}</view>
					<view class="c-content">{{$t('clogin.label.lastlogintime')}}:
						{{$u.timeFormat(sr.userinfo.logintime, 'yyyy/mm/dd hh:MM')}}</view>
				</view>
				<view class="c-album__content" v-if="!$u.clogin.getIsLogined()" @click="clickLogin">
					<view class="c-title" style="padding-top:15px;">{{$t('clogin.btn.clicklogin')}}</view>
					<view class="c-content">{{$t('clogin.label.clicklogintips')}}</view>
				</view>
			</view>
		</view>

		<view class="c-block-full">
			<u-cell-group v-if="sr.menus!=null">
				<u-cell v-for="item in sr.menus" :title="$t(item.name)" isLink :url="item.url"></u-cell>
			</u-cell-group>
			<!-- <u-cell :title="$t('clogin.label.cloginuserloglist')" isLink url="/pages/clogin/cloginuserloglist"></u-cell> -->
		</view>

		<view class="c-block-full">
			<u-cell-group>
				<u-cell :title="$t('clogin.label.userservicetext')" isLink
					url="/pages/clogin/cloginpolicy?type=service"></u-cell>
				<u-cell :title="$t('clogin.label.privacypolicytext')" isLink
					url="/pages/clogin/cloginpolicy?type=private"></u-cell>
				<u-cell :title="$t('clogin.btn.contactme')" isLink url="/pages/clogin/cloginpolicy?type=contactme">
				</u-cell>
			</u-cell-group>
		</view>

		<view class="c-block-transparnt" v-if="$u.clogin.getIsLogined()">
			<button class="active" @click="clickLogout">{{$t('clogin.btn.logout')}}</button>
		</view>

	</view>

</template>

<script>
	export default {
		props: {
			id: {
				type: String
			},
		},
		data() {
			return {
				sp: {},
				param: {},
				sr: {
					userinfo: {},
					menus: [],
				},
			}
		},
		created() {
			let that = this;
			that._initPage();
			uni.$on('onComponentShow', (data) => {
				that._initPage();
			});
		},
		methods: {
			_initPage(isForceDisplay) {
				let that = this;
				uni.setNavigationBarTitle({
					title: that.$t('clogin.tab.me')
				});
				that.$u.c.ajaxget('csmwj/cloginuser/pagemetemplate', {}, function(res) {
					that.sr = res;
					console.log('that.sr=', that.sr);
				});
			},
			clickLogout:function(){
				let that = this;
				that.$u.clogin.logout();
				that._initPage();
			},
			clickLogin: function() {
				let that = this;
				that.$u.clogin.init(that.options, function(token, mobile, third) {
					that._initPage(false);
				});
				if (!that.$u.clogin.getIsLogined()) {
					that.$u.c.showModal({
						content: that.$t('clogin.msg.unloginedtips'),
						success: (res) => {
							if (res.confirm) {
								that.$u.clogin.directLoginPage();
							} else {
								that.$u.clogin.clearSessionUserinfo();
							}
						}
					})
				}
			},
		}
	}
</script>

<style lang="scss">

</style>
